package ru.space_game.entities;

import ru.space_game.core.Game;

/**
 * The entity that represents the players ship
 * 
 * @author Kevin Glass
 * @author Brian Matzon
 */
public class ShipEntity extends Entity {

	private int detectRadius = 1000;

	private Weapon weapon;

	/**
	 * Create a new entity to represent the players ship
	 * 
	 * @param game
	 *            The game in which the ship is being created
	 * @param ref
	 *            The reference to the sprite to show for the ship
	 * @param x
	 *            The initial x location of the player's ship
	 * @param y
	 *            The initial y location of the player's ship
	 */
	public ShipEntity(Game game, String ref, int x, int y) {
		super(game.getSprite(ref), x, y);
		screenX = x;
		screenY = y;
		this.x = x;
		this.y = y;
		visible = true;
		// setup shots, must be greater than max possible amount on the screen
		weapon = new Weapon();
	}

	/**
	 * Request that the ship move itself based on an elapsed amount of time
	 * 
	 * @param delta
	 *            The time that has elapsed since last move (ms)
	 */
	public void move(long delta) {
		super.move(delta);
	}

	/**
	 * Notification that the player's ship has collided with something
	 * 
	 * @param other
	 *            The entity with which the ship has collided
	 */
	public void collidedWith(Entity other) {
		// if its an alien, notify the game that the player
		// is dead
		if (other instanceof AlienEntity || other instanceof ShotEntity) {
			Game.getInstance().notifyDeath();
		}
	}

	/**
	 * Attempt to fire a shot from the player. Its called "try" since we must
	 * first check that the player can fire at this point, i.e. has he/she
	 * waited long enough between shots
	 */
	public boolean canFire() {
		return weapon.canFire();
	}

	public int getDetectRadius() {
		return detectRadius;
	}

	public void fire() {
		weapon.fire(this);
	}

}